import { BaseWindow } from "../../../component/window/BaseWindow";
import { ILockSetUnlockWindow } from "../../../../modules/interfaces/ILockSetUnlockWindow";
import { Language } from "../../../../extend/language/Language";
import { ObjCreate } from "../common/ObjCreate";
import { ELockStatus } from "../../../../Message/Game/ELockStatus";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { EffectManager } from "../../manager/EffectManager";
import { GTextInput } from "../../../../com/mui/controls/GTextInput";
type int = number;
//class LockSetUnlockWindow
    
    export  class LockSetUnlockWindow extends BaseWindow implements ILockSetUnlockWindow
    {
        constructor()
        {
            super();
            setSize(280, 155);
            title = Language.getString(35522);
            titleHeight = 30;
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            var loc1=ObjCreate.createBg(17, 43, 245, 70, this);
            var loc2=ObjCreate.createTextField("", 85, 55, 150, 20, this);
            loc2.filters = [];
            loc2.htmlText = Language.getString(35523);
            this._pwInput = ObjCreate.createGTextInput(60, 80, 160, 20, this);
            this._pwInput.maxChars = 9;
            this._pwInput.restrict = "0-9";
            this._pwInput.displayAsPassword = true;
            var loc3=ObjCreate.createGButton(Language.getString(35227), 80, 118, 50, 25, this);
            loc3.addEventListener(flash.events.MouseEvent.CLICK, this.onSureBtnClickHandler);
            var loc4;
            (loc4 = ObjCreate.createGButton(Language.getString(35407), 155, 118, 50, 25, this)).addEventListener(flash.events.MouseEvent.CLICK, this.onCancelBtnClickHandler);
            return;
        }

        /* internal  */onSureBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=[];
            loc1.push(ELockStatus.convert(ELockStatus._ELockStatusUnLocked), this._pwInput.text);
            Dispatcher.dispatchEvent(new DataEvent(EventName.LockSetLockStatus, loc1));
            return;
        }

        /* internal  */onCancelBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.hide();
            return;
        }

        public /* override */ hide(): void
        {
            super.hide();
            this._pwInput.text = "";
            Dispatcher.dispatchEvent(new DataEvent(EventName.LockNumberKeyboardVisible, false));
            Dispatcher.removeEventListener(EventName.LockNumberKeyboardChange, this.onNumberKeyboardChangeHandler);
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            super.show(arg1, arg2);
            Dispatcher.addEventListener(EventName.LockNumberKeyboardChange, this.onNumberKeyboardChangeHandler);
            EffectManager.hideUIMask();
            return;
        }

        /* internal  */onNumberKeyboardChangeHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as string;
            var loc2=this._pwInput.text.length;
            if (loc1 != "←") 
            {
                if (loc1 != "C") 
                {
                    this._pwInput.text = this._pwInput.text.concat(loc1);
                }
                else 
                {
                    this._pwInput.text = "";
                }
            }
            else 
            {
                this._pwInput.text = this._pwInput.text.slice(0, (loc2 - 1));
            }
            return;
        }

        /* internal */ /* var */_pwInput: GTextInput;
    }
